import axios from 'axios'
import {
    EventBus
} from './EventBus'

axios.defaults.baseURL = 'http://127.0.0.1:4523/m1/6075231-5765596-default'

export class DataManager {
    static getInstance() {
        if (!this.instance) {
            this.instance = new DataManager()
        }
        return this.instance
    }

    getData () {
        // 获取数据
        return new Promise((resolve, reject) => {
            axios.get('/city').then(res => {
                console.log('执行了吗');
                
                resolve(res)
            }).catch(err => {
                reject(err)
            })
        })
    }

    refreshData () {
        // 15s刷新一次数据
        setInterval(async () => {
            const data = await this.getData()
            EventBus.getInstance().emit('refreshHomeCount', data)
        }, 5000)
    }
    
}
